//
//  WarningViewController.m
//  carSecretary
//
//  Created by huangliru on 14-9-9.
//  Copyright (c) 2014年 huangliru. All rights reserved.
//

#import "WarningViewController.h"

@interface WarningViewController ()

@end

@implementation WarningViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //创建一个导航栏
    UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 18, 320, 44)];
    //创建一个导航栏集合
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
    //创建一个左边按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(backButton)];
    //设置导航栏内容
    [navigationItem setTitle:@"报警系统"];
    //把导航栏集合添加入导航栏中，设置动画关闭
    [bar pushNavigationItem:navigationItem animated:NO];
    //把左按钮添加入导航栏集合中
    [navigationItem setLeftBarButtonItem:leftButton];
    bar.backgroundColor = [UIColor grayColor];
    [self.view addSubview:bar];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(110, 200, 100, 40);
    [button setTitle:@"报警提示音" forState:UIControlStateNormal] ;
    [button addTarget:self action:@selector(audioServiceBtu) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

//  自定义c函数，用于播放完后清除音频对象
static void onSystemSoundCompletionCallBack(SystemSoundID ssID,void * obj)
{
    AudioServicesDisposeSystemSoundID(ssID);
}
#pragma mark - BtnPress
-(void)audioServiceBtu
{
    // 获取wav文件的路经
    NSString *wavPath = [[NSBundle mainBundle] pathForResource:@"han" ofType:@"wav"];
    // 封装为url
    NSURL *url = [NSURL fileURLWithPath:wavPath];
    
    // 注册为系统声音
    SystemSoundID ssID = 0;
    // 设置为系统声音
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &ssID);
    // 播放完成后，清除缓存文件
    AudioServicesAddSystemSoundCompletion(ssID, NULL, NULL, onSystemSoundCompletionCallBack, (__bridge void *)self);
    // 播放注册的声音
    AudioServicesPlaySystemSound(ssID);
}

// 导航栏返回按钮
-(void)backButton
{
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
